#ifndef VIDEOOUTPUT_H
#define VIDEOOUTPUT_H

#include <QDebug>

extern "C"
{
#include "SDL.h"
#include "SDL_mutex.h"
#include "libavutil/time.h"
}

#include "avframequeue.h"
#include "avsync.h"

class VideoOutput
{
public:
    VideoOutput(AVSync *avsync, AVRational time_base, AVFrameQueue *frame_queue, int video_width, int video_height);
    ~VideoOutput() ;

    int Init();
    int MainLoop();

    void RefreshLoopWaitEvent(SDL_Event *event);
    void VideoRefresh(double *remaining_time);

private:
    AVFrameQueue *frame_queue_ = nullptr;
    SDL_Event event_;//事件
    SDL_Rect rect_;
    SDL_Window *win_ = nullptr;
    SDL_Renderer *renderer_ = nullptr;
    SDL_Texture *texture_;

    AVSync *avsync_ = nullptr;
    AVRational time_base_;

    int video_width_ = 0;
    int video_height_ = 0;
    uint8_t *yuv_buf = nullptr;
    int yuv_buf_size_ = 0;

//    SDL_mutex mutex_;
};

#endif // VIDEOOUTPUT_H
